package com.android.resetfile.frame;

import com.android.resetfile.controller.Controller;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Main extends Application {
    private Stage stage;
    @Override
    public void start(Stage primaryStage) throws Exception{
      /*  Parent root = FXMLLoader.load(getClass().getResource("index.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root,513 , 313.0));
        primaryStage.show();*/
        stage = primaryStage;


        stage.setTitle("android");
        stage.setMinWidth(513);
        stage.setMinHeight( 313.0);
        gotoLogin();
        primaryStage.show();
    }
    private Initializable replaceSceneContent(String fxml) throws Exception {
        FXMLLoader loader = new FXMLLoader();
        InputStream in = Main.class.getResourceAsStream(fxml);
        loader.setBuilderFactory(new JavaFXBuilderFactory());
        loader.setLocation(Main.class.getResource(fxml));
        Pane page;
        try {
            page = (Pane) loader.load(in);
        } finally {
            in.close();
        }
        Scene scene = new Scene(page, 513,  313.0);

        stage.setScene(scene);
        stage.sizeToScene();

        Initializable initializable = loader.getController();

        return initializable;
    }
    private void gotoLogin() {
        Controller login = null;
        try {
            login = (Controller) replaceSceneContent("index.fxml");
           /* login.setApp(this);*/
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    public static void main(String[] args) throws IOException {
      /* launch(args);
*/
        //检查layout文件中的图片
        //test1();
        //检查src中的图片
        test2();
    }

    private static void test2() {
        File src = new File("E:\\space\\lib\\新建文件夹 (4)\\cnivi_style\\src");
        List<File> fileList = recursionFile(src);
        for(File file : fileList)
        {

        }
    }
    private static List<File> recursionFile(File files)
    {
        List<File> fileList = new ArrayList<File>();
        if (files.isDirectory())
        {
            for(File file : files.listFiles())
            {
                fileList.addAll(recursionFile(file));
            }
        }else
        {
            fileList.add(files);
        }
        return fileList;
    }

    private static void test1() throws IOException {
        long start = System.currentTimeMillis();
        File xmlfile = new File("E:\\space\\lib\\新建文件夹 (4)\\cnivi_style\\res\\layout");
        File pngFile = new File("E:\\space\\lib\\新建文件夹 (4)\\cnivi_style\\res\\drawable-hdpi");
        File[]files = xmlfile.listFiles();
        File[] pngFiles = pngFile.listFiles();
        String str=null;
        String key="@drawable/head_bg";
        List<String> png_names = new ArrayList<String>();
        for(File png:pngFiles)
        {
            String[] names = png.getName().split("\\.");
            String  name = "@drawable/"+names[0];
            boolean png_flag = false;
            for(File f : files)
            {
                BufferedReader bufferedReader = new BufferedReader(new FileReader(f));
                boolean flag = false;
                while ((str=bufferedReader.readLine())!=null)
                {
                    if (str.indexOf(name)>0)
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    png_flag = true;
                    break;
                }
            }
            if (!png_flag)
                png_names.add(png.getName());
        }
        for(String name : png_names)
            System.out.println(name);
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
}
